//
//  LZMyPersonInfoCommonTableViewCell.m
//  laziz_Consumer
//
//  Created by ZhaoDongBo on 2016/10/27.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZMyPersonInfoCommonTableViewCell.h"

#import "Masonry.h"
 

@implementation LZMyPersonInfoCommonTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.backgroundColor = UIColorFromRGB(0xffffff, 1);
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self configView];
        [self addAutoLayoutToCell];
        
        self.headImageView.layer.masksToBounds = YES;
        self.headImageView.layer.cornerRadius = 65/2.0;
        self.headImageView.layer.borderWidth = 1;
        self.headImageView.layer.borderColor = UIColorFromRGB(0xcccccc, 1).CGColor;
       
    }
    return self;
}


- (void)setType:(LZ_MY_INFO_CELL_TYPE)type {
    _type = type;
    
    self.headImageView.hidden = (type != LZ_MY_INFO_CELL_TYPE_HEADIMAGE);
    self.iconImageView.hidden = !self.headImageView.isHidden;
    self.titleLabel.hidden = !self.headImageView.isHidden;
    
    if (type == LZ_MY_INFO_CELL_TYPE_LINKACCOUNT) {
        [self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(self.iconImageView.mas_trailing).with.offset(10);
        }];
        
    }
    else {
        [self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(self.iconImageView.mas_trailing).with.offset(0);
        }];
    }
}

- (void)setThirdPartLeftImage:(UIImage *)leftImage RightImage:(UIImage *)rightImage {
    self.imgThirdPartLeft.image = leftImage;
    self.imgThirdPartRight.image = rightImage;
}

- (void)configView {
    [self.contentView addSubview:self.headImageView];
    [self.contentView addSubview:self.iconImageView];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.subTitleLabel];
    [self.contentView addSubview:self.accessoryImageView];
    [self.contentView addSubview:self.imgThirdPartLeft];
    [self.contentView addSubview:self.imgThirdPartRight];
    [self.contentView addSubview:self.line];
}

- (void)addAutoLayoutToCell {
    
    [self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(10);
        make.centerY.mas_equalTo(self.centerY);
        make.size.mas_equalTo(CGSizeMake(65, 65));
    }];
    
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(10);
        make.centerY.mas_equalTo(self.contentView.centerY);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.iconImageView.mas_trailing).with.offset(10);
        make.centerY.mas_equalTo(self.contentView.centerY);
    }];
    [self.titleLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    
    [self.accessoryImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(-8);
        make.centerY.mas_equalTo(self.contentView.centerY);
        make.size.mas_equalTo(CGSizeMake(12, 12));
    }];
    
    [self.subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView.centerY);
        make.trailing.mas_equalTo(self.accessoryImageView.leading).with.offset(-10);
        make.leading.greaterThanOrEqualTo(self.titleLabel.mas_trailing).offset(10);
    }];
    
    [self.imgThirdPartRight mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(self.subTitleLabel.mas_leading);
        make.centerY.equalTo(0);
        make.width.and.height.equalTo(15);
    }];
    
    [self.imgThirdPartLeft mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(self.imgThirdPartRight.mas_leading).offset(-10);
        make.centerY.equalTo(0);
        make.width.and.height.equalTo(15);
    }];
    
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(0.5);
        make.leading.mas_equalTo(10);
        make.trailing.mas_equalTo(-10);
        make.height.mas_equalTo(0.5);
    }];
}

- (UIImageView *)headImageView {

    if (_headImageView == nil) {
        _headImageView = [[UIImageView alloc] init];
        _headImageView.hidden = YES;
    }
    
    return _headImageView;
}

- (UIImageView*)iconImageView {
    if (_iconImageView == nil) {
        _iconImageView = [[UIImageView alloc] init];
        _iconImageView.hidden = YES;
    }
    
    return _iconImageView;
}

- (UILabel *)titleLabel {

    if (_titleLabel == nil) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor   = UIColorFromRGB(0x333333, 1);
        _titleLabel.font        = [UIFont systemFontOfSize:15];
        _titleLabel.hidden      = YES;
    }
    
    return _titleLabel;
}

- (UILabel *)subTitleLabel {

    if (_subTitleLabel == nil) {
        _subTitleLabel = [[UILabel alloc] init];
        _subTitleLabel.textColor        = UIColorFromRGB(0x999999, 1);
        _subTitleLabel.font             = [UIFont systemFontOfSize:13];
    }
    
    return _subTitleLabel;
}

- (UIImageView *)imgThirdPartLeft {
    if (_imgThirdPartLeft == nil) {
        _imgThirdPartLeft = [[UIImageView alloc] init];
    }
    
    return _imgThirdPartLeft;
}

- (UIImageView *)imgThirdPartRight {
    if (_imgThirdPartRight == nil) {
        _imgThirdPartRight = [[UIImageView alloc] init];
    }
    
    return _imgThirdPartRight;
}

- (UIImageView *)accessoryImageView {

    if (_accessoryImageView == nil) {
        _accessoryImageView = [[UIImageView alloc] init];
        if ([[LZLanguageManager shareInstance] getLanguageType] == LanguageType_Ar) {
             _accessoryImageView.image = [UIImage imageNamed:@"lz_cell_accessoryimage_ar"];
        } else {
             _accessoryImageView.image = [UIImage imageNamed:@"lz_cell_accessoryimage_en"];
        }
    }
    
    return _accessoryImageView;
}

- (UIView *)line {

    if (_line == nil) {
        _line = [[UIView alloc] init];
        _line.backgroundColor = UIColorFromRGB(0xeeeeee, 1);
    }
    
    return _line;
}

@end
